From c98b8c4ce8597b9df911cbcb66f160b848d73542 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 24 Mar 2017 22:21:29 +0100 Subject: [PATCH] Ask for filter specifity instead of 'match' --- src/cargo/ops/cargo_compile.rs | 7 +++++++ src/cargo/ops/cargo_install.rs | 2 +- src/cargo/ops/cargo_run.rs | 37 +++++++++++++++------------------- src/cargo/ops/cargo_test.rs | 3 ++- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index ca68bfe1f..1256787f4 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -382,6 +382,13 @@ impl<'a> CompileFilter<'a> { } } } + + pub fn is_specific(&self) -> bool { + match *self { + CompileFilter::Everything { .. } => false, + CompileFilter::Only { .. } => true, + } + } } #[derive(Clone, Copy, Debug)] diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index a802bffba..d19ac402f 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -358,7 +358,7 @@ fn check_overwrites(dst: &Path, filter: &ops::CompileFilter, prev: &CrateListingV1, force: bool) -> CargoResult>> { - if let CompileFilter::Everything { .. } = *filter { + if !filter.is_specific() { // If explicit --bin or --example flags were passed then those'll // get checked during cargo_compile, we only care about the "build // everything" case here diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index 911b86215..47d18a981 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -1,6 +1,6 @@ use std::path::Path; -use ops::{self, CompileFilter, Packages}; +use ops::{self, Packages}; use util::{self, human, CargoResult, ProcessError}; use core::Workspace; @@ -23,32 +23,27 @@ pub fn run(ws: &Workspace, }; let mut bins = pkg.manifest().targets().iter().filter(|a| { - !a.is_lib() && !a.is_custom_build() && match options.filter { - CompileFilter::Everything { .. } => a.is_bin(), - CompileFilter::Only { .. } => options.filter.matches(a), + !a.is_lib() && !a.is_custom_build() && if !options.filter.is_specific() { + a.is_bin() + } else { + options.filter.matches(a) } }); if bins.next().is_none() { - match options.filter { - CompileFilter::Everything { .. } => { - bail!("a bin target must be available for `cargo run`") - } - CompileFilter::Only { .. } => { - // this will be verified in cargo_compile - } + if !options.filter.is_specific() { + bail!("a bin target must be available for `cargo run`") + } else { + // this will be verified in cargo_compile } } if bins.next().is_some() { - match options.filter { - CompileFilter::Everything { .. } => { - bail!("`cargo run` requires that a project only have one \ - executable; use the `--bin` option to specify which one \ - to run") - } - CompileFilter::Only { .. } => { - bail!("`cargo run` can run at most one executable, but \ - multiple were specified") - } + if !options.filter.is_specific() { + bail!("`cargo run` requires that a project only have one \ + executable; use the `--bin` option to specify which one \ + to run") + } else { + bail!("`cargo run` can run at most one executable, but \ + multiple were specified") } } diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 14b813b3b..b659965d5 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -20,6 +20,7 @@ pub fn run_tests(ws: &Workspace, return Ok(None) } let (test, mut errors) = if options.only_doc { + assert!(options.compile_opts.filter.is_specific()); run_doc_tests(options, test_args, &compilation)? } else { run_unit_tests(options, test_args, &compilation)? @@ -32,7 +33,7 @@ pub fn run_tests(ws: &Workspace, // If a specific test was requested or we're not running any tests at all, // don't run any doc tests. - if let ops::CompileFilter::Only { .. } = options.compile_opts.filter { + if options.compile_opts.filter.is_specific() { match errors.len() { 0 => return Ok(None), _ => return Ok(Some(CargoTestError::new(test, errors))) -- 2.30.2